<template>
  <div>
 
    <div class="container">

        <div class="item12">

            <div class="item1">
                <mymenu></mymenu>
            </div>

            <div class="item2">
            <p>文件管理</p>

              <!-- <div v-for="i,j in data" :key="j">
              <img :src="this.baseURL + i.filepath" alt="" width="60" height="60">{{i.filename}}&emsp;&emsp;<font size="2" color="red"><a @click="del_file(i.filename)">删除</a></font>
              </div>
              <van-uploader :after-read="onRead2">
   
                <van-button color="green">上传文件+</van-button> -->
              <!-- </van-uploader> -->
              <table>
                <tr>
                  <th>选择</th>
                  <th>序号</th>
                  <th>文件名</th>
                  <th>展示</th>
                </tr>
               
                 
                <tr v-for="i,j in data" :key="j">
                <van-checkbox-group v-model="checked" ref="checkboxGroup">
                <td> 
                <van-checkbox :name="i.filename"></van-checkbox>
                </td> 
                </van-checkbox-group>
                <td>{{j}}</td>
                <td>{{i.filename}}</td>
                <td v-html="i.tag"></td>
                
                </tr>
              </table>
               <!-- <van-button color="red" @click="del_file()">删除</van-button>  -->
               <van-button color="red" @click="delall()" size="small">全部删除</van-button>
              <!-- {{checked}} -->
           
             
               <!-- <van-checkbox-group v-model="checkeds" ref="checkboxGroup">
                  <van-checkbox name="a">复选框 a</van-checkbox>
                  <van-checkbox name="b">复选框 b</van-checkbox>
                  <van-checkbox name="c">复选框 c</van-checkbox>
                </van-checkbox-group>

                <van-button type="primary" @click="checkAll">全选</van-button>
                <van-button type="primary" @click="toggleAll">反选</van-button> -->
                
            </div>


        </div>

    </div>

  </div>
</template>

<script>
// 导入子组件
import { time } from 'console';
import mymenu from '../components/menu.vue'

export default {
    
 data() {
    return {
      
        data:'',
        checked:[],
        checkeds:[],


    }



 

  },
  
  components:{
    mymenu
  },
  methods:{
    get_myfile(){
        this.myaxios(this.baseURL + 'file/','get').then(resp=>{
            console.log('获取我的文件',resp)
            if(resp.errcode==0){
                this.data = resp.data
            }
        })
    },
    del_file(){
         this.myaxios(this.baseURL + 'file/','delete',{filename:JSON.stringify(this.checked)}).then(resp=>{
            console.log('删除我的文件',resp)
            if(resp.errcode==0){
                window.location.reload()
            }
        })
    },
    //  onRead2:function(file){
    //     let data = new FormData()
    //     data.append('file',file.file)
       
    //     data.append('token',localStorage.getItem('token'))
        
    //     // 声明文件配置
    //     const axiosconfig = this.axios.create({withCredentials:false}) 
    //     axiosconfig({
    //       method:'post',
    //       url:this.baseURL+'upload/',
    //       data:data

    //     }).then(resp=>{
    //       console.log('上传文件',resp)
    //       if(resp.data.errcode == 0){
    //         window.location.reload()
    //       }
     
    //     })}
    delall(){
      if(this.checked.length == 0){
        this.$toast.fail('请至少选择一个')
        return
      }
      var res = confirm('确定删除么')
      if(res == true){

// var filelist = []
// for(var key in this.checked){
//   // console.log(key)
//   filelist.push(this.checked[key])
//   this.data.splice(key,1)
// }
// console.log('111',this.checked)

        this.myaxios(this.baseURL + 'file/','delete',{filename:JSON.stringify(this.checked)}).then(resp=>{
            console.log('删除我的文件',resp)
            if(resp.errcode==0){
              this.$toast.success(resp.msg)
                window.location.reload()
            }
        })
      }
    }

 },

  
  mounted(){
    
  },
  created(){

    this.get_myfile()

  }

}
</script>


<style scoped>
@import url('../assets/style.css');


</style>

